<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!--{include file='comm/header.tpl'}-->
    <!--{include file='comm/comm_cal.tpl'}-->
    <title>会员短信发送</title>
</head>
<body>

<div class="container">

    <div class="comm_content">

            <div class="search-box">
                <div style="position:relative">
                    <form id="sms_form" class="form-inline" onsubmit="return false;">
                        <table>
                            <tbody>
                            <tr>
                                <td>
                                    手 机 号：<input type="text" id="mobile_id" class="form-control input-sm w150"  name="custID" />
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    短信内容：
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <textarea style="height:80px;width:400px" name="sms_content" id="sms_content" class="form-control"></textarea>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="4">
                                    <input type="button" value="发送" class="btn btn-primary" onclick="customerSms.send();" />&nbsp;&nbsp;
                                    <input type="button" value="重置" class="btn btn-warning" onclick="customerSms.reset();" />
                                </td>
                            </tr>
                            <tr>
                                <td colspan="4">
                                    <br/>
                                    <input type="button" value="导入批量发送" class="btn btn-primary" onclick="customerSms.import();" /> 文件格式，第一列为手机号，第二列为短信内容，无需列标题。
                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </form>
                </div>
            </div>
        </div>
    
</div>
<!--导入 开始-->
<div id="import" style="display: none;">
    <form id="upload_form" name="upload_form" method="post" enctype="multipart/form-data" action="/quanliadmin/app/customer/message.pscript?operFlg=2&message_id=" target="hide_frame">
        <span style="display: inline-block;">
            <input size="130" type="file" id="search_file" name="search_file" style="width:300px">
        </span>
        <input type="button" name="into_sub" id="into_sub" class="btn btn-primary" value="导入">
        <br/>
        <div id="importMsg" style="line-height: 30px;"></div>
        <iframe id="hide_frame" name="hide_frame" style="display: none;"></iframe>
    </form>
</div>
<!--导入 结束-->
<script type="text/javascript">

    var customerSms = {
        //重置输入框内容
        reset: function() {
            document.getElementById('sms_form').reset();
            this.search();
        },
        //重置密码
        send:function(){
            if($("#mobile_id").val()=="")
                {
                    alert("手机号不能为空！");
                    return;
                }
            if(!/^\d{11}$/g.test($("#mobile_id").val()))
            {
                alert("手机号不正确！");
                $("#mobile_id").select();
                return;
            }
            if($("#sms_content").val()=="")
            {
                alert("短信内容不能为空！");
                return;
            }
            E.confirm("您确认要发送短信吗?", function() {
                E.loadding.open('正在发送短信，请稍候...');
                E.ajax_post({
                    url: '/invokingAjax-backend/customer/customerSms.ajax?operFlg=1',
                    data: {
                        mobile:$("#mobile_id").val(),
                        smscontent:$("#sms_content").val()
                    },
                    call: function( o ) {
                        E.loadding.close();
                        if ( o.code == 200 ) {
                            E.alert("发送成功！");
                        } else {
                            E.alert("发送失败！");
                        }
                    }
                });
            });
        },
        //批量导入发短信
        import:function(){
            $("#upload_form").attr("action","/quanliadmin/app/customer/customerSms.pscript?operFlg=2&message_id=");
            E.popup.open({
                id: 'import',
                title: '批量导入短信发送',
                css: 'width: 500px;'
            });
        },
        //信息提示
        importMsg : function (msg, flg){
            if(flg == 0){
                $("#importMsg").css("color","red");
            }else{
                $("#importMsg").css("color","green");
                //更新 input file
                var input_html = $("#search_file").clone();
                $("#search_file").remove();
                $("#searchForm").prepend(input_html);
                msg = "导入成功";
            }
            $("#importMsg").html(msg);
        }

    };
    function getMobileRegex() {
        var regExp = /^\d{11}$/;
        return regExp;
    }
    //导入执行
    $(document).on('click','#into_sub',function(){
        var filename = $('#search_file').val();
        if(filename == ''){
            customerSms.importMsg('请选择上传文件',0);
            return false;
        }

        var basename = filename.split(".");
        if(basename[basename.length-1].toLowerCase() != 'xlsx'){
            customerSms.importMsg('文件类型错误，请选择xlsx文件',0);
            return false;
        }

        $("#importMsg").css("color","black");
        $("#importMsg").text("正在导入，请稍后...");

        $("#upload_form").submit();

    });
</script>
</body>
</html>